package com.zy.project.system.online.entity;

import lombok.Getter;
import lombok.Setter;
import org.apache.shiro.session.mgt.SimpleSession;

/**
 * 在线用户会话属性
 */
@Getter
@Setter
public class OnlineSession extends SimpleSession {

    private static final long serialVersionUID = 1L;

    /** session ID */
    private String sessionId;

    /** 用户ID */
    private String userId;

    /** 用户名称 */
    private String loginName;

    /** 部门名称 */
    private String deptName;

    /** 登录IP地址 */
    private String host;

    /** 浏览器类型 */
    private String browser;

    /** 操作系统 */
    private String os;

    /** 在线状态 */
    private OnlineStatus status = OnlineStatus.on_line;

    /** 属性是否改变 优化session数据同步 */
    private transient boolean attributeChanged = false;

    @Override
    public String getHost() {
        return host;
    }

    @Override
    public void setHost(String host) {
        this.host = host;
    }


    @Override
    public void setAttribute(Object key, Object value) {
        super.setAttribute(key, value);
    }

    @Override
    public Object removeAttribute(Object key) {
        return super.removeAttribute(key);
    }

    public void markAttributeChanged(){
        this.attributeChanged = true;
    }

    public void resetAttributeChanged(){
        this.attributeChanged = false;
    }

    /**
     * 用户在线状态枚举
     */
    public static enum OnlineStatus {
        /** 用户状态 */
        on_line(1,"在线"),
        off_line(0,"离线");

        private Integer key;
        private String info;

        OnlineStatus(Integer key, String info) {
            this.key = key;
            this.info = info;
        }

        public Integer getKey() {
            return key;
        }

        public void setKey(Integer key) {
            this.key = key;
        }

        public String getInfo() {
            return info;
        }

        public void setInfo(String info) {
            this.info = info;
        }
    }

}
